#ifndef _MYCRITICALSECTION_H_
#define _MYCRITICALSECTION_H_

#include "stdafx.h"
#include "readBaumerMex.h"
#include <windows.h>

/// A global instance of this class is used to organize the critical section.
class myCriticalSection {
	private:
		CRITICAL_SECTION handle;
		bool didEnter;
	public:	
		myCriticalSection() {
			//didEnter = false;
			InitializeCriticalSection( &handle );
		}
		~myCriticalSection() {
			DeleteCriticalSection( &handle );
		}
		
		void enter() {
			//if (!didEnter) {
				EnterCriticalSection( &handle );
			//	didEnter = true;
			//}
			//else
			//	throw (char*) "myCriticalSection::enter(): Critical section was already entered.";
		}
		
		void leave() {
			//if (didEnter) {
				LeaveCriticalSection( &handle );
			//	didEnter = false;
			//}
			//else
			//	throw (char*) "myCriticalSection::leave(): Critical section was not entered.";
				
		}
};

#endif